package com.enjoyor.soa.traffic.restt.tpcms.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.enjoyor.soa.traffic.api.dto.tpcms.RltBayonetZoneDto;
import com.enjoyor.soa.traffic.frame.annotation.Auth;
import com.enjoyor.soa.traffic.frame.security.bean.dto.UserDto;
import com.enjoyor.soa.traffic.restt.tpcms.dubbo.IRltBayonetZoneConsumeService;
import com.enjoyor.soa.traffic.restt.tpcms.dubbo.invoke.UbmsDeptBayonetServiceInvoke;
import com.enjoyor.soa.traffic.restt.tpcms.dubbo.invoke.UbmsDicServiceInvoke;
import com.enjoyor.soa.traffic.util.helper.ResultHelper;
import com.enjoyor.soa.traffic.util.pojo.ResultPojo;
import com.enjoyor.soa.traffic.util.pojo.TreeNode;
import com.enjoyor.soa.traffic.util.pojo.ZtreeNode;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@Auth
@RestController
@RequestMapping({ "/rltBayonet" })
@Api("关联卡口操作Controller")
@CrossOrigin
public class RltBayonetZoneController {

    @Autowired
    private IRltBayonetZoneConsumeService rltBayonetZoneConsumeService;

    @Autowired
    private UbmsDeptBayonetServiceInvoke ubmsDeptBayonetServiceInvoke;

    @Autowired
    private UbmsDicServiceInvoke ubmsDicServiceInvoke;
    /**
     * 获取关联卡口列表
     * 
     * @param relationId
     * @param request
     * @return
     */
    @GetMapping(value = { "/getRltBayonetList" }, produces = { "application/json; charset=UTF-8" })
    @ResponseBody
    @ApiOperation(value = "查询关联卡口列表信息", notes = "查询数据库中关联卡口基本信息记录")
    @ApiImplicitParam(name = "relationId", value = "relationId", paramType = "query", dataType = "string")
    public ResultPojo getRltBayonetList(@RequestParam(defaultValue = "", value = "relationId") String relationId,
            HttpServletRequest request) {
        return rltBayonetZoneConsumeService.getRltBayonetList(relationId);//ResultHelper.getResultJson(rltBayonetZoneConsumeService.getRltBayonetList(relationId)).toJSONString();
    }

    /**
     * 关联卡口列表
     * 
     * @param rltBayonetZones
     * @param relationId
     * @param request
     * @return
     */
    @PostMapping(value = { "/insertRltBayonet" }, consumes = { "application/json; charset=UTF-8" }, produces = {
            "application/json; charset=UTF-8" })
    @ResponseBody
    @ApiOperation("关联卡口")
    public ResultPojo insertRltBayonet(@RequestBody List<RltBayonetZoneDto> rltBayonetZones,
            HttpServletRequest request) {
        return rltBayonetZoneConsumeService.insertRltBayonet(rltBayonetZones,
                ((UserDto) request.getAttribute("currentUser")).getPersonName());
    }

    /**
     * 地图单个卡口关联
     * 
     * @param rltBayonetZones
     * @param relationId
     * @param request
     * @return
     */
    @PostMapping(value = { "/insertRltBayonetForOne" }, consumes = { "application/json; charset=UTF-8" }, produces = {
            "application/json; charset=UTF-8" })
    @ResponseBody
    @ApiOperation("关联单个卡口")
    public ResultPojo insertRltBayonetForOne(@RequestBody RltBayonetZoneDto rltBayonetZone,
            HttpServletRequest request) {
        return rltBayonetZoneConsumeService.insertRltBayonetForOne(rltBayonetZone,
                ((UserDto) request.getAttribute("currentUser")).getPersonName());
    }

    /**
     * 取关卡口
     * 
     * @param rltBayonetZone
     * @param request
     * @return
     */
    @DeleteMapping(value = { "/deleteRltBayonet" }, produces = { "application/json; charset=UTF-8" })
    @ResponseBody
    @ApiOperation("取关卡口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "relationId", value = "relationId", paramType = "path", required = true, dataType = "String"),
            @ApiImplicitParam(name = "bayonetId", value = "bayonetId", paramType = "path", required = true, dataType = "String") })
    public ResultPojo deleteRltBayonet(@RequestParam(value = "relationId") String relationId,
            @RequestParam(value = "bayonetId") String bayonetId, HttpServletRequest request) {
        RltBayonetZoneDto rltBayonetZone = new RltBayonetZoneDto();
        rltBayonetZone.setBayonetId(bayonetId);
        rltBayonetZone.setRelationId(relationId);
        return rltBayonetZoneConsumeService.deleteRltBayonet(rltBayonetZone,
                ((UserDto) request.getAttribute("currentUser")).getPersonName());
    }

    /**
     * 部门卡口树Tree
     */
    @GetMapping(value = { "/getDeptBayonetTree" }, produces = { "application/json; charset=UTF-8" })
    @ResponseBody
    @ApiOperation("获取部门卡口树Tree")
    public ResultPojo getDeptBayonetTree(HttpServletRequest request) {
        List<TreeNode> resultList = UbmsDeptBayonetServiceInvoke.bayonetDeptTree;
        if (resultList == null || resultList.size() <= 0) {
            resultList = ubmsDeptBayonetServiceInvoke.getDeptBayonetTree();
        }
        ResultPojo result = ResultHelper.getResult(resultList);
        return result;
    }

    /**
     * 部门卡口树Ztree
     */
    @GetMapping(value = { "/getDeptBayonetZTree" }, produces = { "application/json; charset=UTF-8" })
    @ResponseBody
    @ApiOperation("获取部门卡口树Ztree")
    public ResultPojo getDeptBayonetZTree(HttpServletRequest request) {
        List<ZtreeNode> resultList = UbmsDeptBayonetServiceInvoke.bayonetDeptZTree;
        if (resultList == null || resultList.size() <= 0) {
            resultList = ubmsDeptBayonetServiceInvoke.getDeptBayonetZTree();
        }
        ResultPojo result = ResultHelper.getResult(resultList);
        return result;
    }
    
    /**
	 * 车辆类型树Tree
	 */ 
    @GetMapping(value = { "/getVehtypeTree" }, produces = { "application/json; charset=UTF-8" })
    @ResponseBody
    @ApiOperation("车辆类型树Tree")
    public ResultPojo getVehtypeTree(HttpServletRequest request) {
    	List<TreeNode> resultList = ubmsDicServiceInvoke.getVehtypeTree();
    	ResultPojo result = ResultHelper.getResult(resultList);
        return result;
    }
    
}
